package com.dyy.proxy.jdk.dynamic;

import java.lang.reflect.Proxy;

import com.dyy.proxy.service.AdminService;
import com.dyy.proxy.service.impl.AdminServiceImpl;

/**
 * @author dingyy@jccfc.com
 * @since 2021/12/12 22:07
 */
public class JdkDynamicProxyTest3 {
    public static void main(String[] args) {
        System.out.println("方法三");
        AdminService adminService = new AdminServiceImpl();
        System.out.println("代理目标类：" + adminService.getClass());
        AdminService proxy = (AdminService) Proxy.newProxyInstance(adminService.getClass()
            .getClassLoader(), adminService.getClass()
            .getInterfaces(), (proxy1, method, args1) -> {
                System.out.println("内部类：判断客户是否有权限操作数据变更");
                Object invoke = method.invoke(adminService);
                System.out.println("内部类：记录客户的LOG日志 ");
                return  invoke;
            });
        System.out.println("代理对象:" + proxy.getClass());
        System.out.println("------------------------");
        proxy.update();
        Object o = proxy.find();
        System.out.println("查找的对象：" + o.getClass());
        System.out.println("------------------------");

    }
}
